package com.hytech.utilities;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.MotionEvent;
import android.widget.ImageView;

public class SplashScreenActivity extends Activity {
	
	//time in milliseconds
	private static final long SPLASHTIME = 3000;
	
	public static final String SPLASH_SCREEN_ID = "Splash_Screen";
	
	//handler for splash screen
	private Handler splashHandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			// any message we get is a kill message.
			finish();
			super.handleMessage(msg);
		}
	};
	
	@Override
	public boolean dispatchTouchEvent(MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			splashHandler.removeMessages(0);
			splashHandler.sendMessage(splashHandler.obtainMessage(0));
			return true;
		}
		
		return super.dispatchTouchEvent(event);
			
	};
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.splashscreen);
		ImageView splash = (ImageView) findViewById(R.id.splashscreen);
		splashHandler.removeMessages(0);
		splashHandler.sendMessageDelayed(splashHandler.obtainMessage(0), SPLASHTIME);
		

		// Extras are provided by checkEula() below.
		Intent i = getIntent();
		
		Bundle b = i.getExtras();
		int info_resource_id = b.getInt(SPLASH_SCREEN_ID);
		
		Resources theResources = getResources();
		Drawable splashScreenDrawable = theResources.getDrawable(info_resource_id);
        
		
		splash.setImageDrawable(splashScreenDrawable);
				
    }
}
